﻿using System;
using System.Collections.Generic;
using EXT;
using System.Linq;
using System.Windows.Forms;

namespace BanHangCshap.DanhMuc.gkhtdl63
{
    public partial class frmDSPhieuKhachhang2 : Form
    {
        DateTime xgNgay;
        long xgId_Khachhang2;
        public frmDSPhieuKhachhang2(DateTime xlNgay, long xlId_Khachhang2)
        {
            this.xgId_Khachhang2 = xlId_Khachhang2;
            this.xgNgay = xlNgay;
            InitializeComponent();
        }

        Class.gkhtdl63.BLL.AllInOneBLL xgAllInOneBLL = new BanHangCshap.Class.gkhtdl63.BLL.AllInOneBLL();

        private void frmDSPhieuKhachhang2_Load(object sender, EventArgs e)
        {
            dtpNgay.EditValue = xgNgay;
            gcDSPhieuKhachhang2.DataSource = xgAllInOneBLL.DSPhieuKhachhang2(xgId_Khachhang2, xgNgay);
        }

        public event MyEvent_LoadData Layngay = null;

        DateTime xx = new DateTime();
        bool isChon = false;
        private void btnTruoc_Click(object sender, EventArgs e)
        {
            isChon = true;
            if (gvDSPhieuKhachhang2.RowCount > 0)
            {
                DateTime x = gvDSPhieuKhachhang2.GetFocusedRowCellValue("Ngay").ToDateTime();
                 xx = x.AddSeconds(1);
                //if (Layngay != null)
                //{
                //    Layngay(this, new ELoadData() { IsLoadData = true, Data = xx });
                //}
                this.Close();
            }
            else
            {
                xx = dtpNgay.EditValue.ToDateTime();
                //if (Layngay != null)
                //{
                //    Layngay(this, new ELoadData() { IsLoadData = true, Data = dtpNgay.EditValue.ToDateTime() });
                //}
                this.Close();
            }
        }

        private void btnSau_Click(object sender, EventArgs e)
        {
            DateTime x = gvDSPhieuKhachhang2.GetFocusedRowCellValue("Ngay").ToDateTime();
            DateTime xx = x.AddSeconds(-1);
            if (Layngay != null)
            {
                Layngay(this, new ELoadData() { IsLoadData = true, Data = xx });
            }
            this.Close();
        }

        private void dtpNgay_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index==1)
            {
                gcDSPhieuKhachhang2.DataSource = xgAllInOneBLL.DSPhieuKhachhang2(xgId_Khachhang2, dtpNgay.EditValue.ToDateTime());
            }
        }

        private void frmDSPhieuKhachhang2_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!isChon)
            {
                xx= dtpNgay.EditValue.ToDateTime();
            }
            if (Layngay != null)
            {
                Layngay(this, new ELoadData() { IsLoadData = true, Data = xx });
            }
        }
    }
}
